part of 'cell.dart';

@deprecated
class HorizontalLabelEditCell extends StatefulWidget {
  final String? hint;
  final String? unit;
  final TextStyle? valueStyle;
  final TextStyle? hintStyle;
  final TextStyle? unitStyle;
  final int? maxLength;
  final Widget? title;
  final Widget? rightWidget;
  final bool? isShowBottomLine;
  final double? verticalSpacing;
  final double? horizontalSpacing;
  final EdgeInsetsGeometry? padding;
  final EdgeInsetsGeometry? margin;
  final GestureTapCallback? onTap;
  final Color? background;
  final int? maxLines;
  final int? minLines;
  final List<TextInputFormatter>? formatters;
  final TextInputType? keyboardType;
  final ValueChanged<String>? onChanged;
  final TextEditingController? controller;
  final Color? bottomLineColor;
  final double? bottomLineWidth;
  final bool enable;
  final TextAlign textAlign;

  HorizontalLabelEditCell({
    super.key,
    String? title,
    double? titleWidth,
    TextStyle titleStyle = const TextStyle(fontSize: 16.0, color: Colors.black),
    bool isMust = false,
    this.controller,
    this.hint,
    this.valueStyle,
    this.hintStyle,
    this.maxLength = 20,
    this.rightWidget,
    this.isShowBottomLine,
    this.verticalSpacing,
    this.horizontalSpacing,
    this.padding,
    this.margin,
    this.onTap,
    this.background,
    this.unit,
    this.unitStyle,
    this.maxLines,
    this.minLines,
    this.formatters,
    this.keyboardType,
    this.onChanged,
    this.bottomLineColor,
    this.bottomLineWidth,
    this.textAlign = TextAlign.end,
    this.enable = true,
  }) : this.title = Container(
      width: titleWidth,
      child: Text.rich(
        TextSpan(text: '', style: titleStyle, children: [
          TextSpan(
            text: isMust ? ' * ' : '',
            style: titleStyle.copyWith(color: Colors.red),
          ),
          TextSpan(text: title)
        ]),
        maxLines: 1,
        overflow: TextOverflow.ellipsis,
      ));

  HorizontalLabelEditCell.keyHint({super.key,
    String? title,
    double? titleWidth,
    TextStyle titleStyle = const TextStyle(fontSize: 16.0, color: Colors.black),
    bool isMust = false,
    GestureTapCallback? onHintTap,
    this.controller,
    this.hint,
    this.valueStyle,
    this.hintStyle,
    this.maxLength = 20,
    this.rightWidget,
    this.isShowBottomLine,
    this.verticalSpacing,
    this.horizontalSpacing,
    this.padding,
    this.margin,
    this.onTap,
    this.background,
    this.unit,
    this.unitStyle,
    this.maxLines,
    this.minLines,
    this.formatters,
    this.keyboardType,
    this.onChanged,
    this.bottomLineColor,
    this.bottomLineWidth,
    this.enable = true,
    this.textAlign = TextAlign.end})
      : this.title = GestureDetector(
      onTap: onHintTap,
      child: Container(
        width: titleWidth,
        child: Text.rich(
          TextSpan(text: '', style: titleStyle, children: [
            TextSpan(
              text: isMust ? ' * ' : '',
              style: titleStyle.copyWith(color: Colors.red),
            ),
            TextSpan(text: title)
          ]),
          maxLines: 1,
          overflow: TextOverflow.ellipsis,
        ),
      ));

  HorizontalLabelEditCell.text({super.key,
    String? title,
    double? titleWidth,
    TextStyle titleStyle = const TextStyle(fontSize: 16.0, color: Colors.black),
    bool isMust = false,
    String? text,
    TextEditingController? controller,
    this.hint,
    this.valueStyle,
    this.hintStyle,
    this.maxLength = 20,
    this.rightWidget,
    this.isShowBottomLine,
    this.verticalSpacing,
    this.horizontalSpacing,
    this.padding,
    this.margin,
    this.onTap,
    this.background,
    this.unit,
    this.unitStyle,
    this.maxLines,
    this.minLines,
    this.formatters,
    this.keyboardType,
    this.onChanged,
    this.bottomLineColor,
    this.bottomLineWidth,
    this.enable = true,
    this.textAlign = TextAlign.end})
      : this.title = Container(
      width: titleWidth,
      child: Text.rich(
        TextSpan(text: '', style: titleStyle, children: [
          TextSpan(
            text: isMust ? ' * ' : '',
            style: titleStyle.copyWith(color: Colors.red),
          ),
          TextSpan(text: title)
        ]),
        maxLines: 1,
        overflow: TextOverflow.ellipsis,
      )),
        this.controller = controller ??
            TextEditingController.fromValue(TextEditingValue(
                text: text ?? '', selection: TextSelection.fromPosition(TextPosition(affinity: TextAffinity.downstream, offset: text?.length ?? 0))));

  @override
  State<StatefulWidget> createState() {
    return HorizontalLabelEditCellState();
  }
}
class HorizontalLabelEditCellState extends State<HorizontalLabelEditCell> {
  // late TextEditingController controller;

  @override
  void initState() {
    super.initState();
    // controller = widget.controller ?? TextEditingController();
  }

  @override
  Widget build(BuildContext context) {
    return HorizontalLabelCell(
      enable: widget.enable,
      title: widget.title,
      subTitle: Row(
        children: [
          Expanded(
            child: CupertinoTextField(
              maxLines: widget.maxLines ?? widget.minLines ?? 1,
              minLines: widget.minLines ?? 1,
              padding: const EdgeInsets.all(0.0),
              controller: widget.controller,
              style: widget.valueStyle,
              placeholder: widget.hint ?? '请输入',
              placeholderStyle: widget.hintStyle,
              decoration: const BoxDecoration(),
              keyboardType: widget.keyboardType ?? TextInputType.text,
              inputFormatters: [TextInputLengthLimitingFormatter(widget.maxLength!), ...?widget.formatters],
              textAlign: widget.textAlign,
              onChanged: (str) {
                widget.onChanged?.call(str);
                if (mounted) {
                  setState(() {});
                }
              },
            ),
          ),
          // Expanded(
          //   child: CupertinoTextField(
          //     maxLines: widget.maxLines ?? widget.minLines ?? 1,
          //     minLines: widget.minLines ?? 1,
          //     padding: const EdgeInsets.all(0.0),
          //     controller: widget.controller,
          //     style: widget.valueStyle,
          //     placeholder: widget.hint ?? '请输入',
          //     placeholderStyle: widget.hintStyle,
          //     decoration: const BoxDecoration(),
          //     keyboardType: widget.keyboardType ?? TextInputType.text,
          //     inputFormatters: [TextInputLengthLimitingFormatter(widget.maxLength!), ...?widget.formatters],
          //     textAlign: widget.textAlign,
          //     onChanged: (str) {
          //       widget.onChanged?.call(str);
          //       if (mounted) {
          //         setState(() {});
          //       }
          //     },
          //   ),
          // ),
          Container(
              alignment: Alignment.bottomRight,
              child: Text(
                widget.unit ?? '',
                style: widget.unitStyle,
              ))
        ],
      ),
      bottomLineColor: widget.bottomLineColor,
      bottomLineWidth: widget.bottomLineWidth,
      isShowBottomLine: widget.isShowBottomLine ?? false,
      verticalSpacing: widget.verticalSpacing ?? 0,
      horizontalSpacing: widget.horizontalSpacing ?? 0,
      padding: widget.padding,
      margin: widget.margin,
      onTap: widget.onTap,
      background: widget.background,
      rightWidget: widget.rightWidget,
    );
  }
}
